﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【部门用户】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto部门用户
    /// </summary>
    public abstract class AutoDepartmentUserMapping : BaseMapping<DepartmentUser, DepartmentUserModel, DepartmentUserFilterModel>
    {
        public AutoDepartmentUserMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override DepartmentUserModel Entity2Model(DepartmentUser entity)
        {
            DepartmentUserModel model = new DepartmentUserModel();

            model.DepartmentUserID = entity.DepartmentUserID;
            model.GroupInfoID = entity.GroupInfoID;
            model.DepartmentID = entity.DepartmentID;
            model.UserID = entity.UserID;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override DepartmentUser Model2Entity(DepartmentUserModel model)
        {
            DepartmentUser entity = new DepartmentUser();

            entity.DepartmentUserID = model.DepartmentUserID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.DepartmentID = model.DepartmentID;
            entity.UserID = model.UserID;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<DepartmentUser> FilterModel2Where(DepartmentUserFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._DepartmentUserID.HasValue)
            {
                where = where.And(x => x.DepartmentUserID == filterModel._DepartmentUserID.Value);
            }
            if (filterModel._DepartmentUserIDs.IsNotEmpty() && filterModel._DepartmentUserIDs.Count > 0)
            {
                where = where.And(x => filterModel._DepartmentUserIDs.Contains(x.DepartmentUserID));
            }
            if (filterModel._NotDepartmentUserIDs.IsNotEmpty() && filterModel._NotDepartmentUserIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotDepartmentUserIDs.Contains(x.DepartmentUserID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //部门
            if (filterModel._DepartmentID.HasValue)
            {
                where = where.And(x => x.DepartmentID == filterModel._DepartmentID.Value);
            }
            if (filterModel._DepartmentIDs.IsNotEmpty() && filterModel._DepartmentIDs.Count > 0)
            {
                where = where.And(x => filterModel._DepartmentIDs.Contains(x.DepartmentID));
            }
            if (filterModel._NotDepartmentIDs.IsNotEmpty() && filterModel._NotDepartmentIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotDepartmentIDs.Contains(x.DepartmentID));
            }

            //用户
            if (filterModel._UserID.HasValue)
            {
                where = where.And(x => x.UserID == filterModel._UserID.Value);
            }
            if (filterModel._UserIDs.IsNotEmpty() && filterModel._UserIDs.Count > 0)
            {
                where = where.And(x => filterModel._UserIDs.Contains(x.UserID));
            }
            if (filterModel._NotUserIDs.IsNotEmpty() && filterModel._NotUserIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotUserIDs.Contains(x.UserID));
            }

            return where;
        }
        #endregion
    }
}

